package edu.ccut.saturn.component.impl.node;

import java.util.List;

import edu.ccut.saturn.component.ILogicContext;
import edu.ccut.saturn.component.IParameterContext;
import edu.ccut.saturn.component.IParameterInfo;
import edu.ccut.saturn.component.loader.node.LogicComponentNodeInfoLoader;
import edu.ccut.saturn.component.xml.ISaturnElement;
import edu.ccut.saturn.component.xml.SaturnElement;

/**
 * logic结点的实现类。logic结点出现在logic组件或action组件内部，表示对一个logic组件的引用， 并记录用户配置的运行时参数信息。
 * <p>
 * <code>LogicComponentNodeInfo</code>继承了<code>BaseComponentNodeInfo</code>：
 * <li>字段<code>transactionType</code>：记录了logic结点在运行环境中的事务类型。目前支持两种事务类型，
 * ”supprots“表示在当前事务范围之内；”requireNew“表示不在当前事务范围之内。
 * 
 * @author 谷钰 TODO: is right?
 * @author 温建
 * 
 * @version 1.0 2008.8.19
 * 
 * @see BaseComponentNodeInfo
 * @see ILogicContext
 * @see IParameterContext
 * 
 */
public class LogicComponentNodeInfo extends BaseComponentNodeInfo {

	private String transactionType;

	public LogicComponentNodeInfo(String id, String name, String description,
			String nextId, List<IParameterInfo> parameters, String key,
			String exceptionId, String transactionType, String x, String y) {

		super(id, name, description, nextId, parameters, key, exceptionId, x, y);
		super.setNodeType("logic");
		this.transactionType = transactionType;
	}

	protected IParameterContext createParameterContext(
			ILogicContext logicContext) throws Exception {

		return logicContext.createParameterContext(super.getParameterInfos(),
				transactionType);
	}

	/**
	 * 获得logic结点在运行环境中的事务类型属性的值
	 * 
	 * @return
	 */
	public String getTransactionType() {
		return transactionType;
	}

	@Override
	public ISaturnElement toSaturnElement() {
		ISaturnElement logicElement = (ISaturnElement) super.toSaturnElement();
		logicElement
				.setElementName(LogicComponentNodeInfoLoader.KEY_NODETYPE_LOGIC);

		ISaturnElement transactionType = new SaturnElement(
				LogicComponentNodeInfoLoader.KEY_NODE_START_TRANSACTION);

		transactionType.addAttribute(
				LogicComponentNodeInfoLoader.KEY_LOGIC_TRANSACTION_TYPE,
				this.transactionType);

		logicElement.addSubElement(transactionType);
		return logicElement;
	}

	/**
	 * 设置logic结点在运行环境中的事务类型属性的值
	 * 
	 * @param transactionType
	 */
	public void setTransactionType(String transactionType) {
		this.transactionType = transactionType;
	}
}
